import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate';
Vue.use(Vuex)
const store=new Vuex.Store({
    state:{
        user:{},
        carts:{},
        merchant:{},
        supplier:{},
        product:{},
        SysUser:{}
    },
    mutations:{
        initUser(state,user){
            state.user=user
        },
        initCarts(state,carts){
            state.carts=carts
        },
        initMerchant(state,merchant){
            state.merchant=merchant
        },
        initSupplier(state,supplier){
            state.supplier=supplier
        },
        initProduct(state,product){
            state.product=product
        },
        initSysUser(state,SysUser){
            state.SysUser=SysUser
        },
        clearUser(state){
            state.user={}
        },

    },
    getters:{
        isLogin(state){
            return state.user.nickName !== undefined && state.user.nickName !== null;
        },
        isSysLogin(state){
            return state.SysUser.name !== undefined && state.SysUser.name !== null;
        },
        getUser(state){
            return state.user
        }
    },
    plugins:[createPersistedState()]
})
export default store
